<template>
  <div class="Box">
    <NavTabs :msg="addOrEdit"></NavTabs>
    <van-divider
      :style="{
        color: '#1989fa',
        borderColor: '#1989fa',
        padding: '0 16px',
      }"
    >
      {{ addOrEdit }}</van-divider
    >
    <div class="main">
      <van-form  label-width="8rem">
        <van-cell-group inset>
          <van-field
            v-model="scoreInfo.college"
            name="学院"
            label="学院"
            placeholder="学院"
            :rules="[{ required: true, message: '请输入学院' }]"
          />
          <van-field
            v-model="scoreInfo.cls"
            name="班级"
            label="班级"
            placeholder="班级"
            :rules="[{ required: true, message: '请输入班级' }]"
          />
          <van-field
            v-model="scoreInfo.account"
            name="学籍号"
            label="学籍号"
            placeholder="学籍号"
            :rules="[{ required: true, message: '请输入学籍号' }]"
          />
          <van-field
            v-model="scoreInfo.name"
            name="姓名"
            label="姓名"
            placeholder="姓名"
            :rules="[{ required: true, message: '请输入姓名' }]"
          />
          <van-field
            v-model="scoreInfo.sex"
            name="性别"
            label="性别"
            placeholder="性别"
            :rules="[{ required: true, message: '请输入性别' }]"
          />
          <van-field
            v-model=scoreInfo.height
            name="身高"
            label="身高(厘米)"
            placeholder="身高"
          />
          <van-field
            v-model=scoreInfo.weight
            name="体重"
            label="体重(千克)"
            placeholder="体重"
          />
          <van-field
            v-model=scoreInfo.heightAndWeightScore
            name="身高体重分数"
            label="身高体重分数"
            placeholder="身高体重分数"
          />
          <van-field
            v-model=scoreInfo.heightAndWeightLevel
            name="身高体重等级"
            label="身高体重等级"
            placeholder="身高体重等级"
          />
          <van-field
            v-model=scoreInfo.vitalCapacity
            name="肺活量"
            label="肺活量(毫升)"
            placeholder="肺活量"
          />
          <van-field
            v-model=scoreInfo.vitalCapacityBodyMassScore
            name="肺活量分数"
            label="肺活量分数"
            placeholder="肺活量分数"
          />
          <van-field
            v-model=scoreInfo.vitalCapacityWeightLevel
            name="肺活量等级"
            label="肺活量等级"
            placeholder="肺活量等级"
          />
        
          <van-field
            v-model=scoreInfo.fiftyRun
            name="50米跑"
            label="50米跑(秒 毫秒)"
            placeholder="50米跑"
          />
          <van-field
            v-model=scoreInfo.fiftyRunScore
            name="50米跑分数"
            label="50米跑分数"
            placeholder="50米跑分数"
          />
          <van-field
            v-model=scoreInfo.fiftyRunLevel
            name="50米跑等级"
            label="50米跑等级"
            placeholder="50米跑等级"
          />
          <van-field
            v-model=scoreInfo.thousandRun
            name="1000或800米跑"
            label="1000或800米跑(分 秒)"
            placeholder="1000或800米跑"
          />
          <van-field
            v-model=scoreInfo.thousandRunScore
            name="1000或800米跑分数"
            label="1000或800米跑分数"
            placeholder="1000或800米跑分数"
          />
          <van-field
            v-model=scoreInfo.thousandRunLevel
            name="1000或800米跑等级"
            label="1000或800米跑等级"
            placeholder="1000或800米跑等级"
          />
          <van-field
            v-model=scoreInfo.sittingForwardFlexion
            name="坐位体前屈"
            label="坐位体前屈(厘米)"
            placeholder="坐位体前屈"
          />
          <van-field
            v-model=scoreInfo.sittingForwardFlexionScore
            name="坐位体前屈分数"
            label="坐位体前屈分数"
            placeholder="坐位体前屈分数"
          />
          <van-field
            v-model=scoreInfo.sittingForwardFlexionLevel
            name="坐位体前屈等级"
            label="坐位体前屈等级"
            placeholder="坐位体前屈等级"
          />
          <van-field
            v-model=scoreInfo.standingLongJump
            name="立定跳远"
            label="立定跳远(厘米)"
            placeholder="立定跳远"
          />
          <van-field
            v-model=scoreInfo.standingLongJumpScore
            name="立定跳远分数"
            label="立定跳远分数"
            placeholder="立定跳远分数"
          />
          <van-field
            v-model=scoreInfo.standingLongJumpLevel
            name="立定跳远等级"
            label="立定跳远等级"
            placeholder="立定跳远等级"
          />
          <van-field
            v-model=scoreInfo.pullUpOrOneMinuteSitUps
            label-width="13rem"
            name="引体向上或一分钟仰卧起坐"
            label="引体向上或一分钟仰卧起坐"
            placeholder=""
          />
          <van-field
            v-model=scoreInfo.pullUpOrOneMinuteSitUpsScore
            label-width="13rem"
            name="引体向上或一分钟仰卧起坐分数"
            label="引体向上或一分钟仰卧起坐分数"
            placeholder=""
          />
          <van-field
            v-model=scoreInfo.pullUpOrOneMinuteSitUpsLevel
            label-width="13rem"
            name="引体向上或一分钟仰卧起坐等级"
            label="引体向上或一分钟仰卧起坐等级"
            placeholder=""
          />
          <van-field
            v-model=scoreInfo.totalTestScore
            name="测试总分"
            label="测试总分"
            placeholder="测试总分"
          />
          <van-field
            v-model=scoreInfo.totalTestLevel
            name="总分等级"
            label="总分等级"
            placeholder="总分等级"
          />
        </van-cell-group>
      </van-form>
      <div style="margin: 16px">
        <van-button @click="onSubmit" round block type="primary" native-type="submit">
          提交
        </van-button>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import NavTabs from "../components/NavTabs.vue";
import { useRouter, useRoute } from "vue-router";
import { info,addUserScore } from "../request/api";
import { onMounted, ref } from "@vue/runtime-core";
import { Toast } from "vant";
// interface scoreInfoType {
//   account: any;
//   cls: string;
//   college: string;
//   fiftyRun?: number;
//   fiftyRunLevel?: string;
//   fiftyRunScore?: number;
//   height?: number;
//   heightAndWeightLevel?: string;
//   heightAndWeightScore?: string;
//   id?: number;
//   name: string;
//   pullUpOrOneMinuteSitUps?: number;
//   pullUpOrOneMinuteSitUpsLevel?: string;
//   pullUpOrOneMinuteSitUpsScore?: number;
//   sex: string;
//   sittingForwardFlexion?: number;
//   sittingForwardFlexionLevel?: string;
//   sittingForwardFlexionScore?: number;
//   standingLongJump?: number;
//   standingLongJumpLevel?: string;
//   standingLongJumpScore?: number;
//   thousandRun?: string;
//   thousandRunLevel?: string;
//   thousandRunScore?: number;
//   totalTestLevel?: string;
//   totalTestScore?: number;
//   vitalCapacity?: number;
//   vitalCapacityBodyMassScore?: number;
//   vitalCapacityWeightLevel?: string;
//   weight?: number;
//   schoolYear?:string
// }
const router = useRouter();
const route = useRoute();
const scoreInfo = ref<any>({
  account: "",
  cls: "",
  college: "",
  fiftyRun: "",
  fiftyRunLevel: "",
  fiftyRunScore: "",
  height: "",
  heightAndWeightLevel: "",
  heightAndWeightScore: "",
  // id:"" ,
  name: "",
  pullUpOrOneMinuteSitUps: "",
  pullUpOrOneMinuteSitUpsLevel: "",
  pullUpOrOneMinuteSitUpsScore: "",
  sex: "",
  sittingForwardFlexion: "",
  sittingForwardFlexionLevel: "",
  sittingForwardFlexionScore: "",
  standingLongJump: "",
  standingLongJumpLevel: "",
  standingLongJumpScore: "",
  thousandRun: "",
  thousandRunLevel: "",
  thousandRunScore: "",
  totalTestLevel: "",
  totalTestScore: "",
  vitalCapacity: "",
  vitalCapacityBodyMassScore: "",
  vitalCapacityWeightLevel: "",
  weight: "",
  schoolYear:""
});
const addOrEdit = ref<string>("新增学生成绩");
onMounted(() => {
  // console.log(route.query);
searchInfo(route.query.account,route.query.years)


});
async function searchInfo(nameaccount: any, schoolYear: any) {
  try {
    const { data } = await info(nameaccount, schoolYear);
    // console.log(data);
     if (data.data.data == null) {
      addOrEdit.value = "新增学生成绩 "+ (route.query.years);
      scoreInfo.value.account=route.query.account
       
    } else {
      addOrEdit.value = "修改学生成绩";
      scoreInfo.value = data.data.data;
       scoreInfo.value.schoolYear=route.query.years
      // console.log(scoreInfo.value);
    }
    return data;
  } catch (error) {}
}

function onSubmit() {
  scoreInfo.value.schoolYear=route.query.years
  addUserScore(scoreInfo.value).then(res=>{

    // console.log(res);
  Toast.loading("提交中....")
  if(res.data.code=="200"&&res.data){
    setTimeout(()=>{
       Toast.success("提交成功")
        setTimeout(() => {
            router.go(-1)
           
          }, 1000);
    },1000)
      
  }else{
    Toast.fail("提交失败")
  }


  }).catch(err=>{
      Toast.fail("提交失败")
  });
  
  
}
</script>

<style lang="less" scoped>
.Box {
  .main {
    padding: 1rem 2rem;
    // height: 4rem;
    white-space: nowrap;
    // background-color: aqua;

    padding: 1rem;
    overflow: hidden;
    margin: 1.3rem 1rem;
    border-radius: 0.8rem;
    box-shadow: 0.1rem 0.1rem 0.1rem 0.1rem gainsboro;
  }
}
</style>
